import request from '@/axios'
import type { LoginResultType, LoginUserInfoType, UserLoginType } from './types'

interface RoleParams {
  roleName: string
}

export const loginApi = (data: UserLoginType) => {
  return request.post<LoginResultType>({
    url: '/connect/token',
    data,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}

export const loginOutApi = async () => {
  console.log('退出系统')
  return true
}

export const getUserListApi = ({ params }: AxiosConfig) => {
  return request.get<{
    code: string
    data: {
      // list: UserType[]
      total: number
    }
  }>({ url: '/user/list', params })
}

export const getAdminRoleApi = (params: RoleParams): Promise<AppCustomRouteRecordRaw[]> => {
  return request.get({ url: '/role/list', params })
}

export const getTestRoleApi = (params: RoleParams): Promise<string[]> => {
  return request.get({ url: '/role/list2', params })
}

export const getUserInfo = (): Promise<LoginUserInfoType> => {
  return request.get({ url: '/api/app/profile' })
}
